<template>
  <div class="edit">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>{{form.name}}</span>
        <el-button @click="$router.go(-1)" style="float: right; padding: 3px 0" type="text">返回</el-button>
      </div>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="内容详情" prop="content">
          <Editor v-model="form.content" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm">确定</el-button>
          <el-button @click="cancel">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script>
import Editor from "@/components/Editor";
import {
  getAppWalletDesc,
  updateAppWalletDesc
} from "@/api/system/appWalletDesc";

export default {
  name: "AppWalletDescEdit",
  components: {
    Editor
  },
  data() {
    return {
      // 表单参数
      form: {
        content: ""
      },
      // 表单校验
      rules: {
        content: [{ required: true, message: "请输入内容" }]
      }
    };
  },
  mounted() {
    this.getEditInfo();
  },
  methods: {
    getEditInfo() {
      const id = this.$route.query.id;
      if (id) {
        getAppWalletDesc(id).then(response => {
          this.form = response.data;
        });
      }
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          const postData = {
            ...this.form,
            content: this.filterContent(this.form.content)
          };
          updateAppWalletDesc(postData).then(response => {
            if (response.code === 200) {
              this.msgSuccess("修改成功");
              this.$router.go(-1);
            }
          });
        }
      });
    },
    // 重置按钮
    cancel() {
      this.getEditInfo();
      this.resetForm("form");
    }
  }
};
</script>

